import java.util.*;

class Student {
    public String id;
    public Student(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
public class Test {
    public static void main(String[] args) {
        char[] ch = {'a','b','c'};
        String s1 = new String(ch);
        //intern:把引用它的String类型放入常量池
        s1.intern();
        String s2 = "abc";
        System.out.println(s1 == s2);
    }
    public static void main5(String[] args) {
        String s1 = "hello";
        String s2 = "hello";

        String s3 = new String("hello");
        String s4 = new String("hello");

        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
        System.out.println(s3 == s4);
    }

    public static void main4(String[] args) {
        Student student1 = new Student("123456");
        int hashCode1 = student1.hashCode();
        System.out.println(hashCode1);

        Student student2 = new Student("123456");
        int hashCode2 = student2.hashCode();
        System.out.println(hashCode2);
        System.out.println("======");

        HashBuck2<Student,Integer> hashBuck2 = new HashBuck2<>();
        hashBuck2.push(student1,123);

        System.out.println(hashBuck2.get(student1));

    }
    public static void main3(String[] args) {
        HashBuck hashBuck = new HashBuck();
        hashBuck.push(4,888);
        hashBuck.push(1,888);
        hashBuck.push(2,888);
        hashBuck.push(3,888);
        hashBuck.push(5,888);
        hashBuck.push(6,888);

        hashBuck.push(14,888);

        hashBuck.push(7,888);
        System.out.println("=====");
        System.out.println(hashBuck.get(7));
    }
    public static void main2(String[] args) {
        //Set
        Set<String> set = new TreeSet<>();
        set.add("qinbo");
        set.add("is");
        set.add("大帅比");
        System.out.println(set);
    }
    public static void main1(String[] args) {
        //Map
        Map<String,Integer> map = new TreeMap<>();
        map.put("qinbo",3);
        map.put("is",4);
        map.put("天下第一帅",6);
        //get(),返回key对应的value值
        System.out.println(map.get("qinbo"));
        //getOrDefault(key,默认值),判断是否存在key,存在key返回对应的value值,不存在返回默认值
        System.out.println(map.getOrDefault("lyx",123456));
        //remove(),删除key对应的映射关系
//        System.out.println(map.remove("qinbo"));
//        System.out.println(map.getOrDefault("qinbo",123456));
        //返回所有key-value的映射值
        Set<Map.Entry<String,Integer>> set = map.entrySet();
        for (Map.Entry<String,Integer> entry : set) {
            System.out.println("Key: " + entry.getKey() + "Value: " + entry.getValue());
        }
    }
}
